namespace _5 {

var longestPalindrome = function(s: string): string {
    function isPalindrome(begin: number, end: number): boolean {
        if (begin < 0) return false
        for(; begin < end; begin++, end--) {
            if (s[begin] !== s[end]) return false
        }
        return true
    }

    var res = ""
    for(var i = 0; i < s.length; i++) {
        if (isPalindrome(i - res.length - 1, i)) {
            res = s.substring(i - res.length - 1, i + 1)
        }
        else if (isPalindrome(i - res.length, i)) {
            res = s.substring(i - res.length, i + 1)
        }
    }
    return res
}

console.assert( longestPalindrome('bananas') === 'anana')

}